<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 17-4-8
 * Time: 下午3:18
 */
$router = new Phroute\Phroute\Router();

/**
$router->get(['/example','example_name'], function(){
    return 'This route responds to requests with the GET method at the path /example';
});
**/
$router->get('/blog', function(){
	return 'This route responds to requests with the GET method at the path /example';
});

//$router->get(['/demo/{id:i}/name/{demoname:c}','demo_name'], ['App\Demo\Controllers\HomeController','home']);

//$router->get('/demo/{id:i}/name/{demoname:c}', ['App\Demo\Controllers\HomeController','home']);
$router->addRoute('GET','/demo{id:i}-{oo:c}',['App\Demo\Controllers\HomeController','home']);

//$router->get(['/doo','doo_name'], ['App\Demo\Controllers\HomeController','doo']);

//echo $router->route('demo_name',['5e','fasdd']);

//var_dump ($router->getData());

//$dispatcher = new Phroute\Phroute\Dispatcher($router->getData());
//$response = $router->dispatch($_SERVER['REQUEST_METHOD'], parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));


try
{
    //$response = $dispatcher->dispatch($_SERVER['REQUEST_METHOD'], parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
	$response = $router->dispatch($_SERVER['REQUEST_METHOD'], parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
}
catch (Phroute\Phroute\Exception\HttpMethodNotAllowedException $e)
{
	echo "<h1>Method Not Allowed</h1>";
	echo $e->getMessage();
	exit();
}
catch (Phroute\Phroute\Exception\HttpRouteNotFoundException $e)
{
	echo $e->getMessage();
	exit();
}

echo $response;